using System;
using System.Windows.Forms;

namespace WaterQualityReportSystem
{
    /// <summary>
    /// 硬度测试数据选择对话框
    /// </summary>
    public partial class HardnessTestDataSelectionDialog : Form
    {
        private string[] testDataList;
        private string[] descriptions;
        private string selectedData;

        public string SelectedData => selectedData;

        public HardnessTestDataSelectionDialog(string[] testDataList, string[] descriptions)
        {
            this.testDataList = testDataList;
            this.descriptions = descriptions;
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            this.listBoxTestData = new ListBox();
            this.btnOK = new Button();
            this.btnCancel = new Button();
            this.lblTitle = new Label();
            this.lblDescription = new Label();
            this.SuspendLayout();
            
            // 
            // lblTitle
            // 
            this.lblTitle.AutoSize = true;
            this.lblTitle.Font = new System.Drawing.Font("Microsoft YaHei", 12F, System.Drawing.FontStyle.Bold);
            this.lblTitle.Location = new System.Drawing.Point(12, 9);
            this.lblTitle.Name = "lblTitle";
            this.lblTitle.Size = new System.Drawing.Size(202, 21);
            this.lblTitle.TabIndex = 0;
            this.lblTitle.Text = "选择硬度测试数据";
            
            // 
            // lblDescription
            // 
            this.lblDescription.AutoSize = true;
            this.lblDescription.Location = new System.Drawing.Point(12, 40);
            this.lblDescription.Name = "lblDescription";
            this.lblDescription.Size = new System.Drawing.Size(320, 17);
            this.lblDescription.TabIndex = 1;
            this.lblDescription.Text = "请选择要模拟的硬度测试数据，双击或点击确定按钮执行：";
            
            // 
            // listBoxTestData
            // 
            this.listBoxTestData.FormattingEnabled = true;
            this.listBoxTestData.ItemHeight = 17;
            this.listBoxTestData.Location = new System.Drawing.Point(12, 70);
            this.listBoxTestData.Name = "listBoxTestData";
            this.listBoxTestData.Size = new System.Drawing.Size(460, 225);
            this.listBoxTestData.TabIndex = 2;
            this.listBoxTestData.DoubleClick += this.listBoxTestData_DoubleClick;
            
            // 
            // btnOK
            // 
            this.btnOK.DialogResult = DialogResult.OK;
            this.btnOK.Location = new System.Drawing.Point(316, 310);
            this.btnOK.Name = "btnOK";
            this.btnOK.Size = new System.Drawing.Size(75, 30);
            this.btnOK.TabIndex = 3;
            this.btnOK.Text = "确定";
            this.btnOK.UseVisualStyleBackColor = true;
            this.btnOK.Click += this.btnOK_Click;
            
            // 
            // btnCancel
            // 
            this.btnCancel.DialogResult = DialogResult.Cancel;
            this.btnCancel.Location = new System.Drawing.Point(397, 310);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size(75, 30);
            this.btnCancel.TabIndex = 4;
            this.btnCancel.Text = "取消";
            this.btnCancel.UseVisualStyleBackColor = true;
            
            // 
            // HardnessTestDataSelectionDialog
            // 
            this.AcceptButton = this.btnOK;
            this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
            this.AutoScaleMode = AutoScaleMode.Font;
            this.CancelButton = this.btnCancel;
            this.ClientSize = new System.Drawing.Size(484, 352);
            this.Controls.Add(this.btnCancel);
            this.Controls.Add(this.btnOK);
            this.Controls.Add(this.listBoxTestData);
            this.Controls.Add(this.lblDescription);
            this.Controls.Add(this.lblTitle);
            this.FormBorderStyle = FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "HardnessTestDataSelectionDialog";
            this.StartPosition = FormStartPosition.CenterParent;
            this.Text = "硬度测试数据选择";
            this.ResumeLayout(false);
            this.PerformLayout();
            
            // 填充测试数据列表
            LoadTestData();
        }

        private void LoadTestData()
        {
            for (int i = 0; i < testDataList.Length && i < descriptions.Length; i++)
            {
                listBoxTestData.Items.Add(descriptions[i]);
            }
        }

        private void listBoxTestData_DoubleClick(object sender, EventArgs e)
        {
            if (listBoxTestData.SelectedIndex >= 0)
            {
                selectedData = testDataList[listBoxTestData.SelectedIndex];
                DialogResult = DialogResult.OK;
                Close();
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (listBoxTestData.SelectedIndex >= 0)
            {
                selectedData = testDataList[listBoxTestData.SelectedIndex];
            }
        }

        private ListBox listBoxTestData;
        private Button btnOK;
        private Button btnCancel;
        private Label lblTitle;
        private Label lblDescription;
    }
}